/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ep.m005.ui.controllers;

import com.sun.jersey.api.client.Client;
import com.sun.jersey.api.client.GenericType;
import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.api.client.config.ClientConfig;
import com.sun.jersey.api.client.config.DefaultClientConfig;
import com.sun.jersey.api.json.JSONConfiguration;
import com.vaadin.data.util.BeanItemContainer;
import ep.persistence.entities.T009Medicine;
import java.util.Collection;
import javax.ws.rs.core.UriBuilder;

/**
 *
 * @author Spyros
 */
public class SelectMedicineController {

    private WebResource service;

    public SelectMedicineController() {
        ClientConfig config = new DefaultClientConfig();
        Client client = Client.create(config);
        config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
        service = client.resource(UriBuilder.fromUri("http://localhost:8080/EPrescribing/rest").build());
    }

    public BeanItemContainer<T009Medicine> getMedicineBySubstance(String subName) {
        Collection c = service.path("bl005").path("medsub").queryParam("substance", subName.trim()).
                get(new GenericType<Collection<T009Medicine>>() {
        });
        return new BeanItemContainer<T009Medicine>(T009Medicine.class, c);
    }

    public BeanItemContainer<T009Medicine> getMedicineByMedName(String medName) {
        Collection c = service.path("bl005").path("medname").queryParam("medname", medName.trim()).
                get(new GenericType<Collection<T009Medicine>>() {
        });
        return new BeanItemContainer<T009Medicine>(T009Medicine.class, c);
    }
}
